package com.sky.chapter1.join;

/**
 * description: 主线程等待子线程执行完毕, 才开始往下走
 * 例如 :
 * idea  一条线程加载 Java 代码 一条线程 加载插件
 * 直到 二者都加载完毕之后, idea 才能给用户使用;
 * <p>
 * Author by cqb, Date on 2020/6/27，23:14
 */
public class joinDemo {


    public static void main(String[] args) throws InterruptedException {
        //创建线程threadOne
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child ThreadOne over!");
            }
        });
        //创建线程threadTwo
        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child ThreadTwo over!");
            }
        });
        //启动子线程
        threadOne.start();
        threadTwo.start();
        System.out.println("wait all child thread over!");

        //等待子线程执行完毕，返回
        threadOne.join();
        threadTwo.join();

        System.out.println("all child thread over!");
    }
}
